package paketGUI;

import java.util.HashMap;

import paketDB.DatabaseHandler;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import eu.mvmnt.golfingapp.R;

public class MainMenuScreen extends Activity implements OnClickListener,
		DialogInterface.OnClickListener {

	/**
	 * @uml.property name="btnNewRound"
	 * @uml.associationEnd
	 */
	private Button btnNewRound;
	/**
	 * @uml.property name="btnOptions"
	 * @uml.associationEnd
	 */
	private Button btnOptions;
	/**
	 * @uml.property name="btnRules"
	 * @uml.associationEnd
	 */
	private Button btnRules;
	/**
	 * @uml.property name="btnStatistics"
	 * @uml.associationEnd
	 */
	private Button btnStatistics;

	@Override
	public void onBackPressed() {
		AlertDialog.Builder logoutBuilder = new AlertDialog.Builder(this);
		logoutBuilder.setTitle("Logout?");
		logoutBuilder.setMessage("Are you sure you want to logout?");

		logoutBuilder.setPositiveButton("Logout now", this);
		logoutBuilder.setNegativeButton("Cancel", this);

		AlertDialog logout = logoutBuilder.create();
		logout.show();
	}

	@Override
	public void onClick(DialogInterface dialog, int which) {
		if (which == DialogInterface.BUTTON_POSITIVE) {
			Intent i = new Intent(this, LoginScreen.class);
			i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(i);
			finish();
		} else if (which == DialogInterface.BUTTON_NEGATIVE) {
			dialog.dismiss();
		}
	}

	@Override
	public void onClick(View v) {
		if (v.getId() == R.id.btnOptions) {
			Intent intent = new Intent(v.getContext(), OptionsScreen.class);
			startActivityForResult(intent, 0);
		}

	}

	@SuppressWarnings("rawtypes")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_menu);

		btnNewRound = (Button) findViewById(R.id.btnNewRound);
		btnOptions = (Button) findViewById(R.id.btnOptions);
		btnStatistics = (Button) findViewById(R.id.btnStatistics);
		btnRules = (Button) findViewById(R.id.btnRules);

		btnNewRound.setOnClickListener(this);
		btnOptions.setOnClickListener(this);
		btnStatistics.setOnClickListener(this);
		btnRules.setOnClickListener(this);

		DatabaseHandler db = new DatabaseHandler(getApplicationContext());
		HashMap user = new HashMap();
		user = db.getUserDetails();

		final TextView txtWelcomeUser = (TextView) findViewById(R.id.txtWelcomeUser);
		txtWelcomeUser.setText("Hallo " + user.get("Vorname").toString()); //$NON-NLS-1$ //$NON-NLS-2$
	}

}
